package mybatisSQLUntil;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlSessionConnection {

	private static SqlSessionFactory sqlSessionFactory = null;
	// 静态代码块,初始化执行
	static {
		try {
			InputStream inputStream = Resources.getResourceAsStream("resources/springmybatis-config.xml");
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private SqlSessionConnection() {
	}// 构建单例

	public static SqlSession getSqlseeeion() {
		return sqlSessionFactory.openSession();
	}
}
